
/**
 * Module dependencies.
 */

var express         = require('express')
  , routes          = require('./routes')
  , user            = require('./routes/user')
  , pages           = require('./routes/page')
  , http            = require('http')
  , path            = require('path')
  , mustacheExpress = require('mustache-express')
  , events          = require('events');

var app = express();

global.Application = new events.EventEmitter();
Application.root_dir = __dirname;


// all environments
app.engine('mustache', mustacheExpress())
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'mustache');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('less-middleware')({ src: __dirname + '/public' }));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

for(var page in pages){
    app.get('/page/' + page, pages[page]);
}
app.get('/page/:username/profile', pages.profile);
app.get('/user/:id/intro', user.intro);

app.get('/assets_javascript.js', require('./routes/assets')["assets_javascript.js"]);
app.get('/assets_style.css', require('./routes/assets')["assets_style.css"]);


http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
